<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/1/15
 * Time: 13:43
 */

namespace App\Presenters;


use App\Models\Post;
use Illuminate\Pagination\LengthAwarePaginator;
use Lang;

class PostPresenter
{
    /**
     * @param $post Post
     * @return string
     */
    public function showPublished($post){
        if ($post && $post instanceof Post){
            if ($post->published=='1'){
                return "<span class='label label-success'>".Lang::get('label.post.published')."</span>";
            }elseif($post->published=='2'){
                return "<span class='label label-danger'>".Lang::get('label.post.unPublished')."</span>";
            }
        }
        return '';
    }

    /**
     * @param LengthAwarePaginator $posts
     * @return string
     */
    public function showPaginate($posts){
        if ($posts && $posts instanceof LengthAwarePaginator){
            $links=$posts->links();
            $currentPage=$posts->currentPage();
            $lastPage=$posts->lastPage();
            $total=$posts->total();
//            $result=trans('pagination.result',['currentPage'=>$currentPage,
//                                                'lastPage'=>$lastPage,
//                                                'total'=>$total,
//            ]);
            return <<<EOT
            <div class="box-footer clearfix">
                <div class="pull-right">
                    $links
                </div>
                Showing $currentPage to $lastPage  of $total entries
            </div>
EOT;
        }else{
            return '';
        }
    }
}